<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateBuysTable extends Migration
{
	private $tableName = 'buys';
	private $tableComment = '求购管理表';
	private $primaryKey = 'id';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function (Blueprint $table) {
			$table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('商品id');
            $table->string('title', 100)->comment('求购标题');
            $table->mediumText('des')->comment('求购描述')->nullable();
            $table->mediumText('remark')->comment('描述')->nullable();
            $table->string('author', 255)->comment('发布者')->nullable();
            $table->string('nickname', 255)->comment('发布者昵称')->nullable();
            $table->unsignedTinyInteger('author_id')->comment('发布者id')->default(0);
            $table->string('avatar', 500)->comment('发布者头像')->nullable();
            $table->string('phone', 11)->comment('发布者联系方式')->nullable();
            $table->unsignedTinyInteger('status')->comment('状态，1进行中，0不通过,2已完成，3失效')->default(0);
            $table->string('endDate', 100)->comment('截至时间')->nullable();
            $table->unsignedInteger('need_nums')->comment('求购数量数')->default(0);
            $table->string('size', 255)->comment('尺寸')->nullable();
            $table->mediumText('refund_msg')->comment('拒绝审核原因')->nullable();
            $table->timestamps();

			if (env('DB_CONNECTION') == 'oracle') {
				$table->comment = $this->tableComment;
			}
		});

		if (env('DB_CONNECTION') == 'mysql') {
			DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists($this->tableName);
		if (env('DB_CONNECTION') == 'oracle') {
			$sequence = DB::getSequence();
			$sequence->drop(strtoupper($this->tableName . '_' . $this->primaryKey . '_SEQ'));
		}
	}
}
